/*
Problem Description
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.
 

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
 

Output
For each test case, you should output the text which is processed.
 

Sample Input
3
olleh !dlrow
m'I morf .udh
I ekil .mca
 

Sample Output
hello world!
I'm from hdu.
I like acm.
 */
package com.yuan.algorithms.training201607;

import java.io.BufferedInputStream;
import java.util.Scanner;

/**
 * @author YouYuan
 * @contact 1265161633@qq.com
 * @date 2016年8月5日 上午9:03:43
 * @descript 
 */
public class HDU1062TextReverse {

	static Scanner in = new Scanner(new BufferedInputStream(System.in));
	public static void main(String[] args) {
		while(in.hasNext()) {
			int n = in.nextInt();
			in.nextLine();
			for (int i = 0; i < n; i++) {
				String str = in.nextLine();
				String result = reverseStr(str);
				System.out.println(result);
			}
		}
	}
	private static String reverseStr(String str) {
		StringBuilder result = new StringBuilder();
		StringBuilder temp = new StringBuilder();
		for (int i = 0, len = str.length(); i < len; i++) {
			char c = str.charAt(i);
			if (c != ' ') {
				temp.append(c);
			} else {
				result.append(temp.reverse());
				result.append(c);
				temp = new StringBuilder();
			}
		}
		if (temp.length() != 0) {
			result.append(temp.reverse());
		}
		return result.toString();
		
	}
}
